package com.woniuxy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Author: ideaAdmin
 * TODO:文件上传控制器
 * Date: 2022/2/9:13:26
 * Description:
 */
@Controller
@RequestMapping("/file")
public class FileController {

    @RequestMapping("upload")
    //多个不同名字的文件上传接收
    public String fileUpload(String username, MultipartFile upload1,MultipartFile upload2) throws IOException {
        System.out.println(username);
        //获得上传文件的名字
        String filename = upload1.getOriginalFilename();
        upload1.transferTo(new File("Z:\\7Z\\" + filename));

        String filename2 = upload2.getOriginalFilename();
        upload2.transferTo(new File("Z:\\7Z\\" + filename2));
        return "index";
    }

    @RequestMapping("uploads")
    //多个同名字的文件上传接收 接收的参数名必须一致
    public String fileUpload(String username, MultipartFile[] upload) throws IOException {
        System.out.println(username);
        for(MultipartFile uploadFile : upload){
            //获得上传文件的名字
            String filename = uploadFile.getOriginalFilename();
            uploadFile.transferTo(new File("Z:\\7Z\\" + filename));
        }
        return "index";
    }
}
